package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.common.anno.Logs;
import com.qk.dto.role.RoleDTO;
import com.qk.entity.Role;
import com.qk.management.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 *
 * @author blusr
 * @version 1.0
 * @date 2025/10/7 19:47
 */
@Slf4j
@RestController
@RequestMapping("/roles")
@SuppressWarnings("all")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping
    public Result getRoles(RoleDTO roleDto) {
        log.info("getRoles: {}", roleDto);
        return Result.success(roleService.page(roleDto));
    }

    @Logs("添加角色")
    @PostMapping
    public Result addRole(@RequestBody Role role) {
        log.info("addRole: {}", role);
        roleService.addRole(role);
        return Result.success();
    }

    @Logs("删除角色")
    @DeleteMapping("/{id}")
    public Result deleteRole(@PathVariable Long id) {
        log.info("deleteRole: {}", id);
        roleService.deleteRole(id);
        return Result.success();
    }

    @Logs("获取角色详情")
    @GetMapping("/{id}")
    public Result getRole(@PathVariable Long id) {
        log.info("getRole: {}", id);
        return Result.success(roleService.getRole(id));
    }

    @Logs("更新角色")
    @PutMapping
    public Result updateRole(@RequestBody Role role) {
        log.info("updateRole: {}", role);
        roleService.updateRole(role);
        return Result.success();
    }


    @GetMapping("/list")
    public Result getRoleList() {
        log.info("getRoleList");
        return Result.success(roleService.getRoles());
    }
}
